class videoPageUtil{

    _legnth = 0;
    constructor(pageContent) {
      this.pageContentList = pageContent+'.list'
      this.pageContentPageNum = pageContent+'.pageNum'
      this.pageContentTotal = pageContent+'.total';
      this.pageContentRows = pageContent+'.rows';
    //   this.pageContentLoading = pageContent+'.loading';
    //   this.pageContentLoaded = pageContent+'.loaded';
      this.pageContent = pageContent
    }
    load(pageHandler,that,pageContent){
      this._pageHandler = pageHandler;
      let list = that.data[this.pageContent]['list'];
      this._pageHandler().then(res => {
        var rows = res.rows.map((url, index) => ({ id: index +this._legnth+1, url:url.fileUrl,title:url.title,
        desc:url.videoDesc}))
        console.log(rows)
        this._legnth = this._legnth+res.rows.length
        console.log(this._legnth)
        let newList = list.concat(rows);
        if(newList.length == res.total){
        //   that.setData({[this.pageContentLoading]:true,[this.pageContentLoaded]:false})
        }

        that.setData({
          [this.pageContentRows]:newList,
          [this.pageContentList]:rows,
          [this.pageContentPageNum]:that.data[this.pageContent]['pageNum']+1,
          [this.pageContentTotal]:res.total
        })
      });
    }
  
    init(that){
      that.setData({[this.pageContentList]:[],[this.pageContentPageNum]:1,[this.pageContentTotal]:0})
    }
  
    onPullDownRefresh(that){
    //   wx.stopPullDownRefresh() 
    //   that.setData({[this.pageContentList]:[],[this.pageContentPageNum]:1,[this.pageContentTotal]:0,[this.pageContentLoading]:true,[this.pageContentLoaded]:true})
    //   that.onLoad();
    }
  
    onReachBottom(that,index){
        console.log(this._legnth-4  +'-----'+index)
      if(this._legnth-4 == index){
        this.load(this._pageHandler,that)
      }
    }
    
  }
  export default  videoPageUtil;